/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entityopinions;

import com.aliasi.chunk.Chunking;
import com.aliasi.util.AbstractExternalizable;
import com.sleepycat.je.DatabaseException;
import entityopinions.ComputePMI.Kernel;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Serializable;

/**
 *
 * @author Diogo
 */
public class TestLexChunker {

    static void write(String modelPath) throws IOException, DatabaseException{

        LexChunker lexChunker = new LexChunker(Kernel.Gaussian, 1, "C:/Users/Diogo/Desktop/Cache");
        //String sentence = "My opinion on a coward like Timmy Reyes is very negative.";
        //lexChunker.chunk(sentence);
        File modelFile = new File(modelPath);
        AbstractExternalizable.serializeTo((Serializable) lexChunker,modelFile);

    }

    void countSentencesEntities() throws FileNotFoundException, IOException{
        File directory = new File("C:/Users/Diogo/Desktop/textos-anotados");
        int countSenteces = 0, countPos = 0, countNeg = 0, countNeu = 0;
        File[] files = directory.listFiles();

        for(int i = 0; i < files.length; i++){
            File f = files[i];
            BufferedReader br = new BufferedReader(new FileReader(f));
            String line = br.readLine();
            while(line != null){
                
                if(line.indexOf("<s>") != -1){
                    countSenteces++;
                }
                while(line.indexOf("ENTITY_POS") != -1){
                    countPos++;
                    line = line.substring(line.indexOf("ENTITY_POS") + 12);
                }
                while(line.indexOf("ENTITY_NEG")!= -1){
                    countNeg++;
                    line = line.substring(line.indexOf("ENTITY_NEG") + 12);
                }
                while(line.indexOf("ENTITY_NEU")!= -1){
                    countNeu++;
                    line = line.substring(line.indexOf("ENTITY_NEU") + 12);
                }
                line = br.readLine();
            }
        }
        System.out.println("Numero de frases:\n" + countSenteces + "\nNumero Entidades Positivas:\n" +
                countPos + "\nNumero Entidades Negativas:\n" + countNeg + "\nEntidades Neutras\n" +
                countNeu);
    }

    public static void main(String args[]) throws IOException, ClassNotFoundException, DatabaseException{

        //OpinionChunkParser ocp = new OpinionChunkParser();
        //PrintStream out = new PrintStream(new FileOutputStream(new File("c:/users/diogo/desktop/teste.txt")));
        //ocp.pmiInCorpus("c:/users/diogo/desktop/Cache", "c:/users/diogo/desktop/textos-anotados",
        //        out, "EN", 0.5);

        TestLexChunker t = new TestLexChunker();
        t.write("c:/users/diogo/desktop/xpto.lexchunker");
        //t.countSentencesEntities();
        /*
        File modelFile = new File("c:/users/diogo/desktop/teste.lexchunker");
        @SuppressWarnings("unchecked")
        LexChunker lexChunker = (LexChunker) AbstractExternalizable.readObject(modelFile);
        String sentence = "My opinion on a coward like Timmy Reyes is very negative.";
        Chunking chunking = lexChunker.chunk(sentence);
        System.out.println(chunking);*/
    }

}
